#include <bits/stdc++.h>
using namespace std;
#define MAXN 300005
#define lson pos << 1
#define rson pos << 1 | 1
int N, Q, a[MAXN], pre[MAXN];

char str[MAXN];

int Right[MAXN];

int lowbit(int x) {
	return x & (-x);
}

void update1(int x, int add) {
	while (x <= N) {
		Right[x] += add;
		x += lowbit(x);
	}
}

int query1(int x) {
	int ans = 0;
	while (x) {
		ans += Right[x];
		x -= lowbit(x);
	}
	return ans;
}

int gao(int l, int r) {
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		int sum = query1(mid);
		if (sum >= 1) {
			r = mid;
		} else {
			l = mid;
		}
	}
	if (query1(l) > 0) return l;
	if (query1(r) > 0) return r;
}

struct Node {
	int sum, add;
} p[MAXN << 2];

void pushdown(int pos) {
	if (p[pos].add) {
		p[lson].sum += p[pos].add;
		p[rson].sum += p[pos].add;
		p[lson].add = p[rson].add = p[pos].add;
		p[pos].add = 0;
	}
}

void pushup(int pos) {
	p[pos].sum = min(p[lson].sum, p[rson].sum);
}

void build(int l, int r, int pos) {
	p[pos].sum = p[pos].add = 0;
	if (l == r) {
		p[pos].sum = pre[l];
		p[pos].add = 0;
		return ;
	}
	int mid = (l + r) >> 1;
	build(l, mid, lson);
	build(mid + 1, r, rson);
	pushdown(pos);
}

void update(int l, int r, int L, int R, int pos, int add) {
	if (l <= L && R <= r) {
		p[pos].add += add;
		p[pos].sum += add;
		return ;
	}
	pushdown(pos);
	int mid = (L + R) >> 1;
	if (mid >= l) {
		update(l, r, L, mid, lson, add);
	}
	if (mid < r) {
		update(l, r, mid + 1, R, rson, add);
	}
	pushup(pos);
}

int query(int l, int r, int L, int R, int pos) {
	if (l <= L && R <= r) {
		return p[pos].sum;
	}
	pushdown(pos);
	int mid = (L + R) >> 1;
	int ans = -1;
	if (mid >= l) {
		int q = query(l, r, L, mid, lson);
		if (ans == -1) {
			ans = q;
		} else {
			ans = min(ans, q);
		}
	}
	if (mid < r) {
		int q = query(l, r, mid + 1, R, rson);
		if (ans == -1) {
			ans = q;
		} else {
			ans = min(ans, q);
		}
	}
	pushup(pos);
	return ans;
}

int solve(int l, int r) {
	int R = r;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		int q = query(mid, R, 1, N, 1);
		if (q > 1) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	int q;
	q = query(l, R, 1, N, 1);
	if (q > 1) return l;
	q = query(r, R, 1, N, 1);
	if (q > 1) return r;
}

void work() {
	memset(Right, 0, sizeof(Right));
	memset(pre, 0, sizeof(pre));
	scanf("%s", str + 1);
	for (int i = 1; i <= N; i ++) {
		a[i] = str[i] == '(' ? 1 : - 1;
		if (a[i] == -1) {
			update1(i, 1);
		}
		pre[i] = pre[i - 1] + a[i];
	}
	build(1, N, 1);
	/*
	   for (int i = 1; i <= N; i ++) {
	   printf("%c%c", a[i] == 1 ? '(' : ')', " \n"[i == N]);
	   }
	   for (int i = 1; i <= N; i ++) {
	   printf("%d%c", query(i, i, 1, N, 1), " \n"[i == N]);
	   }*/
	for (int i = 1; i <= Q; i ++) {
		int op, ans;
		scanf("%d", &op);
		ans = op;
		if (a[op] == 1) {
			a[op] = -1;
			update1(op, 1);
			int pos = gao(1, op);
			printf("%d\n", pos);
			update1(pos, -1);
			update(pos, N, 1, N, 1, 2);
			update(op, N, 1, N, 1, -2);
			a[pos] = 1;
		} else {
			update1(op, -1);
			update(op, N, 1, N, 1, 2);
			a[op] = 1;
			int pos = solve(1, op);
			a[pos] = -1;
			update1(pos, 1);
			update(pos, N, 1, N, 1, -2);
			printf("%d\n", pos);
		}
		/*
		   for (int j = 1; j <= N; j ++) {
		   printf("%c%c", a[j] == 1 ? '(' : ')', " \n"[j == N]);
		   }
		   for (int j = 1; j <= N; j ++) {
		   printf("%d%c", query(j, j, 1, N, 1), " \n"[j == N]);
		   }*/
	}
}

int main() {
#ifdef __SKT__
	freopen("in", "r", stdin);
#endif
	while (scanf("%d %d", &N, &Q) != EOF) {
		work();
	}
	return 0;
}

